function domReady(func) {
	if(domReady.done)	return func();
	if(domReady.timer)	domReady.ready.push(func);
	else {
		addEvent(window, "load", isDomReady);
		domReady.ready = [func];
		domReady.timer = setInterval( isDomReady, 50 );
	}
}
function isDomReady() {
	if (domReady.done)	return true;
	if( document && document.getElementsByTagName && document.getElementById && document.body ) {
		clearInterval(domReady.timer);
		domReady.timer = null;
		for (var i=0; i<domReady.ready.length ; i++ )
			domReady.ready[i]();

		domReady.ready = null;
		domReady.done = true;
	}
}

function stopBubble(e) {
	if (e && e.stopPropagation)	e.stopPropagation();
	else	window.event.cancelBubble = true;
}
function stopDefault(e) {
	if (e && e.preventDefault)	e.preventDefault();
	else	window.event.returnValue = false;
	return false;
}

function addEvent(element, type, handler) {
        if (!handler.$$guid) handler.$$guid = addEvent.guid++;
        if (!element.events) element.events = {};
        var handlers = element.events[type];
        if (!handlers) {
                handlers = element.events[type] = {};
                if (element["on" + type]) {
                        handlers[0] = element["on" + type];
                }
        }
        handlers[handler.$$guid] = handler;
        element["on" + type] = handleEvent;
};
addEvent.guid = 1;

function removeEvent(element, type, handler) {
        if (element.events && element.events[type]) {
                delete element.events[type][handler.$$guid];
        }
};

function handleEvent(event) {
        var returnValue = true;
        event = event || fixEvent(window.event);
        var handlers = this.events[event.type];
        for (var i in handlers) {
                this.$$handleEvent = handlers[i];
                if (this.$$handleEvent(event) === false) {
                        returnValue = false;
                }
        }
        return returnValue;
};

function fixEvent(event) {
        event.preventDefault = fixEvent.preventDefault;
        event.stopPropagation = fixEvent.stopPropagation;
        return event;
};
fixEvent.preventDefault = function() {
        this.returnValue = false;
};
fixEvent.stopPropagation = function() {
        this.cancelBubble = true;
};

function mousePosition(e) {
	e = e || window.event;
	return {"x": e.pageX || e.clientX + document.body.scrollLeft,
				"y" : e.pageY || e.clientY + document.body.scrollTop};
}